package main;

import java.util.Map;
import java.util.Map.Entry;

import main.Instance.Weight;
import utils.Pair;
import utils.topology.DepthFirstPaths;
import utils.topology.Graph;

public class Verifier {

	public static boolean verify(Map<Integer, Boolean> nodes, Map<Pair<Integer, Integer>, Weight> edges){
		Graph graph = new Graph(nodes.size());
		
		for (Entry<Pair<Integer, Integer>, Weight> edge : edges.entrySet()) {
			Pair<Integer, Integer> p = edge.getKey();
			if (edge.getValue().equals(Weight.LONG)){
				if (nodes.get(p.first)){
					graph.addDirectedEdge(p.first-1, p.second-1);
				}
				if (nodes.get(p.second)){
					graph.addDirectedEdge(p.second-1, p.first-1);
				}
				
			}else{
				graph.addEdge(p.first-1, p.second-1);
			}
		}
		return isConnected(graph);
	}
	
	
	public static boolean isConnected(Graph graph){
		for (int s=0; s<graph.V(); s++){
			DepthFirstPaths dfp = new DepthFirstPaths(graph, s);
			
			for(int t=0; t<graph.V(); t++){
				if (!dfp.hasPathTo(t))
					return false;
			}
		}
		
		return true;
	}
}
